package cn.wzvtc.solf14;

import cn.wzvtc.solf14.Service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created by Administrator on 2016/3/4.
 */
@ComponentScan  //扫描包
@RestController
@EnableAutoConfiguration
@CrossOrigin(origins = {"http://127.0.0.1:8020","http://localhost:63342","http://localhost:63343","*"},methods={RequestMethod.GET,RequestMethod.OPTIONS,RequestMethod.POST})
public class Main {

    @RequestMapping("/home")  //域名：localhost:8080/home
    String home() {
        return "[{\"user\":\"wpl\"}]";
    }

    @Autowired
    CourseService courseService;

    @RequestMapping("/getCourse")  //域名：localhost:8080/get
    List get(int week, String clazz) {
        return courseService.findByWeekAndClazz(week, clazz);
    }

    @RequestMapping("/insert")  //域名：localhost:8080/get
    String insert(String addr, String t, String name, int day, int startTime, int endTime, int week, String clazz) {
        return courseService.insert(addr,  t,  name,  day,  startTime,  endTime,  week,  clazz);
    }

    @RequestMapping(value="/getSchool",produces = "application/json; charset=UTF-8")  //域名：localhost:8080/getSchool
    String getSchool() {
        return "[{\"name\": \"温州职业技术学院\"},{\"name\": \"温州大学\"},{\"name\": \"温州医科大学\" }]";
    }

    @RequestMapping("/login")  //域名：localhost:8080/getSchool
    String login(String username, String password) {
        if(!username.equals("Yuicon")){
            return "[{\"msg\": \"登陆失败\"}]";
        }else if(password.equals("123456")){
            return "[{\"msg\": \"serUser\"}]";
        }else{
            return "[{\"msg\": \"登陆失败\"}]";
        }

    }

    public static void main(String[] args) throws Exception {
        SpringApplication.run(Main.class, args);
    }

}
